package com.nsxy.common.beans;

import java.io.Serializable;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * @author 潜行的青衣
 * @see
 */
@SuppressWarnings("serial")
public abstract class BaseEntity<ID extends Serializable> implements Serializable {

	public abstract ID getId();

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(this.getId()).toHashCode();
	}

	
	@Override
	@SuppressWarnings("unchecked")
	public boolean equals(Object obj) {
		if(obj == null || !this.getClass().isInstance(obj)) {
			return false;
		}
		BaseEntity<ID> entity = (BaseEntity<ID>) obj;
		if(this.getId() == null || entity.getId() == null) {
			return false;
		}
		return new EqualsBuilder()
				.append(this.getId(), entity.getId()).isEquals();
	}
	
}
